cognitiveclass.ai logo

Extracting and Visualizing Stock Data

Description

Extracting essential data from a dataset and displaying it is a necessary part of data science; therefore individuals can make correct decisions based on the data. In this assignment, you will extract some stock data, you will then display this data in a graph.

Table of Contents

  • Define a Function that Makes a Graph
  • Question 1: Use yfinance to Extract Stock Data
  • Question 2: Use Webscraping to Extract Tesla Revenue Data
  • Question 3: Use yfinance to Extract Stock Data
  • Question 4: Use Webscraping to Extract GME Revenue Data
  • Question 5: Plot Tesla Stock Graph
  • Question 6: Plot GameStop Stock Graph

Estimated Time Needed: 30 min


In [1]:
!pip install yfinance==0.1.67
#!pip install pandas==1.3.3
#!pip install requests==2.26.0
!mamba install bs4==4.10.0 -y
#!pip install plotly==5.3.1
Requirement already satisfied: yfinance==0.1.67 in /opt/conda/envs/Python-3.8-main/lib/python3.8/site-packages (0.1.67)
Requirement already satisfied: numpy>=1.15 in /opt/conda/envs/Python-3.8-main/lib/python3.8/site-packages (from yfinance==0.1.67) (1.19.2)
Requirement already satisfied: pandas>=0.24 in /opt/conda/envs/Python-3.8-main/lib/python3.8/site-packages (from yfinance==0.1.67) (1.2.4)
Requirement already satisfied: requests>=2.20 in /opt/conda/envs/Python-3.8-main/lib/python3.8/site-packages (from yfinance==0.1.67) (2.25.1)
Requirement already satisfied: lxml>=4.5.1 in /opt/conda/envs/Python-3.8-main/lib/python3.8/site-packages (from yfinance==0.1.67) (4.7.1)
Requirement already satisfied: multitasking>=0.0.7 in /opt/conda/envs/Python-3.8-main/lib/python3.8/site-packages (from yfinance==0.1.67) (0.0.10)
Requirement already satisfied: python-dateutil>=2.7.3 in /opt/conda/envs/Python-3.8-main/lib/python3.8/site-packages (from pandas>=0.24->yfinance==0.1.67) (2.8.1)
Requirement already satisfied: pytz>=2017.3 in /opt/conda/envs/Python-3.8-main/lib/python3.8/site-packages (from pandas>=0.24->yfinance==0.1.67) (2021.1)
Requirement already satisfied: six>=1.5 in /opt/conda/envs/Python-3.8-main/lib/python3.8/site-packages (from python-dateutil>=2.7.3->pandas>=0.24->yfinance==0.1.67) (1.15.0)
Requirement already satisfied: certifi>=2017.4.17 in /opt/conda/envs/Python-3.8-main/lib/python3.8/site-packages (from requests>=2.20->yfinance==0.1.67) (2021.10.8)
Requirement already satisfied: urllib3<1.27,>=1.21.1 in /opt/conda/envs/Python-3.8-main/lib/python3.8/site-packages (from requests>=2.20->yfinance==0.1.67) (1.26.6)
Requirement already satisfied: idna<3,>=2.5 in /opt/conda/envs/Python-3.8-main/lib/python3.8/site-packages (from requests>=2.20->yfinance==0.1.67) (2.8)
Requirement already satisfied: chardet<5,>=3.0.2 in /opt/conda/envs/Python-3.8-main/lib/python3.8/site-packages (from requests>=2.20->yfinance==0.1.67) (3.0.4)
/usr/bin/sh: mamba: command not found
In [2]:
import yfinance as yf
import pandas as pd
import requests
from bs4 import BeautifulSoup
import plotly.graph_objects as go
from plotly.subplots import make_subplots

Define Graphing Function

In this section, we define the function make_graph. You don't have to know how the function works, you should only care about the inputs. It takes a dataframe with stock data (dataframe must contain Date and Close columns), a dataframe with revenue data (dataframe must contain Date and Revenue columns), and the name of the stock.

In [3]:
def make_graph(stock_data, revenue_data, stock):
    fig = make_subplots(rows=2, cols=1, shared_xaxes=True, subplot_titles=("Historical Share Price", "Historical Revenue"), vertical_spacing = .3)
    stock_data_specific = stock_data[stock_data.Date <= '2021--06-14']
    revenue_data_specific = revenue_data[revenue_data.Date <= '2021-04-30']
    fig.add_trace(go.Scatter(x=pd.to_datetime(stock_data_specific.Date, infer_datetime_format=True), y=stock_data_specific.Close.astype("float"), name="Share Price"), row=1, col=1)
    fig.add_trace(go.Scatter(x=pd.to_datetime(revenue_data_specific.Date, infer_datetime_format=True), y=revenue_data_specific.Revenue.astype("float"), name="Revenue"), row=2, col=1)
    fig.update_xaxes(title_text="Date", row=1, col=1)
    fig.update_xaxes(title_text="Date", row=2, col=1)
    fig.update_yaxes(title_text="Price ($US)", row=1, col=1)
    fig.update_yaxes(title_text="Revenue ($US Millions)", row=2, col=1)
    fig.update_layout(showlegend=False,
    height=900,
    title=stock,
    xaxis_rangeslider_visible=True)
    fig.show()

Question 1: Use yfinance to Extract Stock Data

Using the Ticker function enter the ticker symbol of the stock we want to extract data on to create a ticker object. The stock is Tesla and its ticker symbol is TSLA.

In [4]:
tesla = yf.Ticker("TSLA")

Using the ticker object and the function history extract stock information and save it in a dataframe named tesla_data. Set the period parameter to max so we get information for the maximum amount of time.

In [5]:
tesla_info=tesla.info
tesla_info
tesla_data = tesla.history(period="max")
tesla_data
Out[5]:
Open High Low Close Volume Dividends Stock Splits
Date
2010-06-29 3.800000 5.000000 3.508000 4.778000 93831500 0 0.0
2010-06-30 5.158000 6.084000 4.660000 4.766000 85935500 0 0.0
2010-07-01 5.000000 5.184000 4.054000 4.392000 41094000 0 0.0
2010-07-02 4.600000 4.620000 3.742000 3.840000 25699000 0 0.0
2010-07-06 4.000000 4.000000 3.166000 3.222000 34334500 0 0.0
... ... ... ... ... ... ... ...
2022-02-01 935.210022 943.700012 905.000000 931.250000 24379400 0 0.0
2022-02-02 928.179993 931.500000 889.409973 905.659973 22264300 0 0.0
2022-02-03 882.000000 937.000000 880.520020 891.140015 26285200 0 0.0
2022-02-04 897.219971 936.500000 881.169983 923.320007 24472600 0 0.0
2022-02-07 923.789978 947.770020 907.390076 913.071228 12134179 0 0.0

2924 rows × 7 columns

Reset the index using the reset_index(inplace=True) function on the tesla_data DataFrame and display the first five rows of the tesla_data dataframe using the head function. Take a screenshot of the results and code from the beginning of Question 1 to the results below.

In [6]:
tesla_data.reset_index(inplace=True)
tesla_data.head()
Out[6]:
Date Open High Low Close Volume Dividends Stock Splits
0 2010-06-29 3.800 5.000 3.508 4.778 93831500 0 0.0
1 2010-06-30 5.158 6.084 4.660 4.766 85935500 0 0.0
2 2010-07-01 5.000 5.184 4.054 4.392 41094000 0 0.0
3 2010-07-02 4.600 4.620 3.742 3.840 25699000 0 0.0
4 2010-07-06 4.000 4.000 3.166 3.222 34334500 0 0.0

Question 2: Use Webscraping to Extract Tesla Revenue Data

Use the requests library to download the webpage https://www.macrotrends.net/stocks/charts/TSLA/tesla/revenue. Save the text of the response as a variable named html_data.

In [7]:
url = "https://www.macrotrends.net/stocks/charts/TSLA/tesla/revenue?utm_medium=Exinfluencer&utm_source=Exinfluencer&utm_content=000026UJ&utm_term=10006555&utm_id=NA-SkillsNetwork-Channel-SkillsNetworkCoursesIBMDeveloperSkillsNetworkPY0220ENSkillsNetwork23455606-2021-01-01.html"
html_data  = requests.get(url).text

Parse the html data using beautiful_soup.

In [8]:
soup = BeautifulSoup(html_data, 'html.parser')

Using BeautifulSoup or the read_html function extract the table with Tesla Quarterly Revenue and store it into a dataframe named tesla_revenue. The dataframe should have columns Date and Revenue.

Click here if you need help locating the table ``` Below is the code to isolate the table, you will now need to loop through the rows and columns like in the previous lab soup.find_all("tbody")[1] If you want to use the read_html function the table is located at index 1 ```
In [9]:
tables = soup.find_all('table')
tables
for index,table in enumerate(tables):
    if ("Tesla Quarterly Revenue" in str(table)):
        table_index = index
print(table_index)

print(tables[table_index].prettify())

tesla_revenue = pd.DataFrame(columns=["Date","Revenue"])

for row in tables[table_index].tbody.find_all("tr"):
    col = row.find_all("td")
    if (col != []):
        date = col[0].text.strip()
        revenue = col[1].text.strip()
    
    # Finally we append the data of each row to the table
    tesla_revenue = tesla_revenue.append({"Date":date, "Revenue":revenue}, ignore_index=True)
    
tesla_revenue
1
<table class="historical_data_table table">
 <thead>
  <tr>
   <th colspan="2" style="text-align:center">
    Tesla Quarterly Revenue
    <br/>
    <span style="font-size:14px;">
     (Millions of US $)
    </span>
   </th>
  </tr>
 </thead>
 <tbody>
  <tr>
   <td style="text-align:center">
    2021-09-30
   </td>
   <td style="text-align:center">
    $13,757
   </td>
  </tr>
  <tr>
   <td style="text-align:center">
    2021-06-30
   </td>
   <td style="text-align:center">
    $11,958
   </td>
  </tr>
  <tr>
   <td style="text-align:center">
    2021-03-31
   </td>
   <td style="text-align:center">
    $10,389
   </td>
  </tr>
  <tr>
   <td style="text-align:center">
    2020-12-31
   </td>
   <td style="text-align:center">
    $10,744
   </td>
  </tr>
  <tr>
   <td style="text-align:center">
    2020-09-30
   </td>
   <td style="text-align:center">
    $8,771
   </td>
  </tr>
  <tr>
   <td style="text-align:center">
    2020-06-30
   </td>
   <td style="text-align:center">
    $6,036
   </td>
  </tr>
  <tr>
   <td style="text-align:center">
    2020-03-31
   </td>
   <td style="text-align:center">
    $5,985
   </td>
  </tr>
  <tr>
   <td style="text-align:center">
    2019-12-31
   </td>
   <td style="text-align:center">
    $7,384
   </td>
  </tr>
  <tr>
   <td style="text-align:center">
    2019-09-30
   </td>
   <td style="text-align:center">
    $6,303
   </td>
  </tr>
  <tr>
   <td style="text-align:center">
    2019-06-30
   </td>
   <td style="text-align:center">
    $6,350
   </td>
  </tr>
  <tr>
   <td style="text-align:center">
    2019-03-31
   </td>
   <td style="text-align:center">
    $4,541
   </td>
  </tr>
  <tr>
   <td style="text-align:center">
    2018-12-31
   </td>
   <td style="text-align:center">
    $7,226
   </td>
  </tr>
  <tr>
   <td style="text-align:center">
    2018-09-30
   </td>
   <td style="text-align:center">
    $6,824
   </td>
  </tr>
  <tr>
   <td style="text-align:center">
    2018-06-30
   </td>
   <td style="text-align:center">
    $4,002
   </td>
  </tr>
  <tr>
   <td style="text-align:center">
    2018-03-31
   </td>
   <td style="text-align:center">
    $3,409
   </td>
  </tr>
  <tr>
   <td style="text-align:center">
    2017-12-31
   </td>
   <td style="text-align:center">
    $3,288
   </td>
  </tr>
  <tr>
   <td style="text-align:center">
    2017-09-30
   </td>
   <td style="text-align:center">
    $2,985
   </td>
  </tr>
  <tr>
   <td style="text-align:center">
    2017-06-30
   </td>
   <td style="text-align:center">
    $2,790
   </td>
  </tr>
  <tr>
   <td style="text-align:center">
    2017-03-31
   </td>
   <td style="text-align:center">
    $2,696
   </td>
  </tr>
  <tr>
   <td style="text-align:center">
    2016-12-31
   </td>
   <td style="text-align:center">
    $2,285
   </td>
  </tr>
  <tr>
   <td style="text-align:center">
    2016-09-30
   </td>
   <td style="text-align:center">
    $2,298
   </td>
  </tr>
  <tr>
   <td style="text-align:center">
    2016-06-30
   </td>
   <td style="text-align:center">
    $1,270
   </td>
  </tr>
  <tr>
   <td style="text-align:center">
    2016-03-31
   </td>
   <td style="text-align:center">
    $1,147
   </td>
  </tr>
  <tr>
   <td style="text-align:center">
    2015-12-31
   </td>
   <td style="text-align:center">
    $1,214
   </td>
  </tr>
  <tr>
   <td style="text-align:center">
    2015-09-30
   </td>
   <td style="text-align:center">
    $937
   </td>
  </tr>
  <tr>
   <td style="text-align:center">
    2015-06-30
   </td>
   <td style="text-align:center">
    $955
   </td>
  </tr>
  <tr>
   <td style="text-align:center">
    2015-03-31
   </td>
   <td style="text-align:center">
    $940
   </td>
  </tr>
  <tr>
   <td style="text-align:center">
    2014-12-31
   </td>
   <td style="text-align:center">
    $957
   </td>
  </tr>
  <tr>
   <td style="text-align:center">
    2014-09-30
   </td>
   <td style="text-align:center">
    $852
   </td>
  </tr>
  <tr>
   <td style="text-align:center">
    2014-06-30
   </td>
   <td style="text-align:center">
    $769
   </td>
  </tr>
  <tr>
   <td style="text-align:center">
    2014-03-31
   </td>
   <td style="text-align:center">
    $621
   </td>
  </tr>
  <tr>
   <td style="text-align:center">
    2013-12-31
   </td>
   <td style="text-align:center">
    $615
   </td>
  </tr>
  <tr>
   <td style="text-align:center">
    2013-09-30
   </td>
   <td style="text-align:center">
    $431
   </td>
  </tr>
  <tr>
   <td style="text-align:center">
    2013-06-30
   </td>
   <td style="text-align:center">
    $405
   </td>
  </tr>
  <tr>
   <td style="text-align:center">
    2013-03-31
   </td>
   <td style="text-align:center">
    $562
   </td>
  </tr>
  <tr>
   <td style="text-align:center">
    2012-12-31
   </td>
   <td style="text-align:center">
    $306
   </td>
  </tr>
  <tr>
   <td style="text-align:center">
    2012-09-30
   </td>
   <td style="text-align:center">
    $50
   </td>
  </tr>
  <tr>
   <td style="text-align:center">
    2012-06-30
   </td>
   <td style="text-align:center">
    $27
   </td>
  </tr>
  <tr>
   <td style="text-align:center">
    2012-03-31
   </td>
   <td style="text-align:center">
    $30
   </td>
  </tr>
  <tr>
   <td style="text-align:center">
    2011-12-31
   </td>
   <td style="text-align:center">
    $39
   </td>
  </tr>
  <tr>
   <td style="text-align:center">
    2011-09-30
   </td>
   <td style="text-align:center">
    $58
   </td>
  </tr>
  <tr>
   <td style="text-align:center">
    2011-06-30
   </td>
   <td style="text-align:center">
    $58
   </td>
  </tr>
  <tr>
   <td style="text-align:center">
    2011-03-31
   </td>
   <td style="text-align:center">
    $49
   </td>
  </tr>
  <tr>
   <td style="text-align:center">
    2010-12-31
   </td>
   <td style="text-align:center">
    $36
   </td>
  </tr>
  <tr>
   <td style="text-align:center">
    2010-09-30
   </td>
   <td style="text-align:center">
    $31
   </td>
  </tr>
  <tr>
   <td style="text-align:center">
    2010-06-30
   </td>
   <td style="text-align:center">
    $28
   </td>
  </tr>
  <tr>
   <td style="text-align:center">
    2010-03-31
   </td>
   <td style="text-align:center">
    $21
   </td>
  </tr>
  <tr>
   <td style="text-align:center">
    2009-12-31
   </td>
   <td style="text-align:center">
   </td>
  </tr>
  <tr>
   <td style="text-align:center">
    2009-09-30
   </td>
   <td style="text-align:center">
    $46
   </td>
  </tr>
  <tr>
   <td style="text-align:center">
    2009-06-30
   </td>
   <td style="text-align:center">
    $27
   </td>
  </tr>
  <tr>
   <td style="text-align:center">
    2008-12-31
   </td>
   <td style="text-align:center">
   </td>
  </tr>
 </tbody>
</table>

Out[9]:
Date Revenue
0 2021-09-30 $13,757
1 2021-06-30 $11,958
2 2021-03-31 $10,389
3 2020-12-31 $10,744
4 2020-09-30 $8,771
5 2020-06-30 $6,036
6 2020-03-31 $5,985
7 2019-12-31 $7,384
8 2019-09-30 $6,303
9 2019-06-30 $6,350
10 2019-03-31 $4,541
11 2018-12-31 $7,226
12 2018-09-30 $6,824
13 2018-06-30 $4,002
14 2018-03-31 $3,409
15 2017-12-31 $3,288
16 2017-09-30 $2,985
17 2017-06-30 $2,790
18 2017-03-31 $2,696
19 2016-12-31 $2,285
20 2016-09-30 $2,298
21 2016-06-30 $1,270
22 2016-03-31 $1,147
23 2015-12-31 $1,214
24 2015-09-30 $937
25 2015-06-30 $955
26 2015-03-31 $940
27 2014-12-31 $957
28 2014-09-30 $852
29 2014-06-30 $769
30 2014-03-31 $621
31 2013-12-31 $615
32 2013-09-30 $431
33 2013-06-30 $405
34 2013-03-31 $562
35 2012-12-31 $306
36 2012-09-30 $50
37 2012-06-30 $27
38 2012-03-31 $30
39 2011-12-31 $39
40 2011-09-30 $58
41 2011-06-30 $58
42 2011-03-31 $49
43 2010-12-31 $36
44 2010-09-30 $31
45 2010-06-30 $28
46 2010-03-31 $21
47 2009-12-31
48 2009-09-30 $46
49 2009-06-30 $27
50 2008-12-31

Execute the following line to remove the comma and dollar sign from the Revenue column.

In [10]:
tesla_revenue["Revenue"] = tesla_revenue['Revenue'].str.replace(',|\$',"")
/tmp/wsuser/ipykernel_789/349343550.py:1: FutureWarning: The default value of regex will change from True to False in a future version.
  tesla_revenue["Revenue"] = tesla_revenue['Revenue'].str.replace(',|\$',"")

Execute the following lines to remove an null or empty strings in the Revenue column.

In [11]:
tesla_revenue.dropna(inplace=True)

tesla_revenue = tesla_revenue[tesla_revenue['Revenue'] != ""]

Display the last 5 row of the tesla_revenue dataframe using the tail function. Take a screenshot of the results.

In [12]:
tesla_revenue.tail()
Out[12]:
Date Revenue
44 2010-09-30 31
45 2010-06-30 28
46 2010-03-31 21
48 2009-09-30 46
49 2009-06-30 27

Question 3: Use yfinance to Extract Stock Data

Using the Ticker function enter the ticker symbol of the stock we want to extract data on to create a ticker object. The stock is GameStop and its ticker symbol is GME.

In [13]:
gme = yf.Ticker("GME")

Using the ticker object and the function history extract stock information and save it in a dataframe named gme_data. Set the period parameter to max so we get information for the maximum amount of time.

In [14]:
gme_info=gme.info
gme_info
gme_data = gme.history(period="max")
gme_data
Out[14]:
Open High Low Close Volume Dividends Stock Splits
Date
2002-02-13 6.480513 6.773399 6.413183 6.766666 19054000 0.0 0.0
2002-02-14 6.850828 6.864294 6.682503 6.733000 2755400 0.0 0.0
2002-02-15 6.733001 6.749833 6.632006 6.699336 2097400 0.0 0.0
2002-02-19 6.665670 6.665670 6.312187 6.430015 1852600 0.0 0.0
2002-02-20 6.463683 6.648840 6.413185 6.648840 1723200 0.0 0.0
... ... ... ... ... ... ... ...
2022-02-01 113.010002 116.650002 108.260002 112.599998 3461900 0.0 0.0
2022-02-02 110.349998 111.860001 98.059998 100.040001 3279100 0.0 0.0
2022-02-03 101.500000 106.940002 97.709999 99.230003 2677500 0.0 0.0
2022-02-04 99.010002 104.000000 95.080002 102.339996 1904200 0.0 0.0
2022-02-07 102.989998 105.190002 98.769997 99.664497 956181 0.0 0.0

5032 rows × 7 columns

Reset the index using the reset_index(inplace=True) function on the gme_data DataFrame and display the first five rows of the gme_data dataframe using the head function. Take a screenshot of the results and code from the beginning of Question 3 to the results below.

In [15]:
gme_data.reset_index(inplace=True)
gme_data.head()
Out[15]:
Date Open High Low Close Volume Dividends Stock Splits
0 2002-02-13 6.480513 6.773399 6.413183 6.766666 19054000 0.0 0.0
1 2002-02-14 6.850828 6.864294 6.682503 6.733000 2755400 0.0 0.0
2 2002-02-15 6.733001 6.749833 6.632006 6.699336 2097400 0.0 0.0
3 2002-02-19 6.665670 6.665670 6.312187 6.430015 1852600 0.0 0.0
4 2002-02-20 6.463683 6.648840 6.413185 6.648840 1723200 0.0 0.0

Question 4: Use Webscraping to Extract GME Revenue Data

Use the requests library to download the webpage https://www.macrotrends.net/stocks/charts/GME/gamestop/revenue. Save the text of the response as a variable named html_data.

In [16]:
url1 = "https://www.macrotrends.net/stocks/charts/GME/gamestop/revenue?utm_medium=Exinfluencer&utm_source=Exinfluencer&utm_content=000026UJ&utm_term=10006555&utm_id=NA-SkillsNetwork-Channel-SkillsNetworkCoursesIBMDeveloperSkillsNetworkPY0220ENSkillsNetwork23455606-2021-01-01.html"
html_data  = requests.get(url1).text

Parse the html data using beautiful_soup.

In [17]:
soup = BeautifulSoup(html_data, 'html.parser')

Using BeautifulSoup or the read_html function extract the table with GameStop Quarterly Revenue and store it into a dataframe named gme_revenue. The dataframe should have columns Date and Revenue. Make sure the comma and dollar sign is removed from the Revenue column using a method similar to what you did in Question 2.

Click here if you need help locating the table ``` Below is the code to isolate the table, you will now need to loop through the rows and columns like in the previous lab soup.find_all("tbody")[1] If you want to use the read_html function the table is located at index 1 ```
In [18]:
tables = soup.find_all('table')
tables
for index,table in enumerate(tables):
    if ("GameStop Quarterly Revenue" in str(table)):
        table_index = index
print(table_index)

print(tables[table_index].prettify())

gme_revenue = pd.DataFrame(columns=["Date","Revenue"])

for row in tables[table_index].tbody.find_all("tr"):
    col = row.find_all("td")
    if (col != []):
        date = col[0].text.strip()
        revenue = col[1].text.strip()
    
    # Finally we append the data of each row to the table
    gme_revenue = gme_revenue.append({"Date":date, "Revenue":revenue}, ignore_index=True)
    
gme_revenue

gme_revenue["Revenue"] = gme_revenue['Revenue'].str.replace(',|\$',"")

gme_revenue.dropna(inplace=True)

gme_revenue = gme_revenue[gme_revenue['Revenue'] != ""]
1
<table class="historical_data_table table">
 <thead>
  <tr>
   <th colspan="2" style="text-align:center">
    GameStop Quarterly Revenue
    <br/>
    <span style="font-size:14px;">
     (Millions of US $)
    </span>
   </th>
  </tr>
 </thead>
 <tbody>
  <tr>
   <td style="text-align:center">
    2021-10-31
   </td>
   <td style="text-align:center">
    $1,297
   </td>
  </tr>
  <tr>
   <td style="text-align:center">
    2021-07-31
   </td>
   <td style="text-align:center">
    $1,183
   </td>
  </tr>
  <tr>
   <td style="text-align:center">
    2021-04-30
   </td>
   <td style="text-align:center">
    $1,277
   </td>
  </tr>
  <tr>
   <td style="text-align:center">
    2021-01-31
   </td>
   <td style="text-align:center">
    $2,122
   </td>
  </tr>
  <tr>
   <td style="text-align:center">
    2020-10-31
   </td>
   <td style="text-align:center">
    $1,005
   </td>
  </tr>
  <tr>
   <td style="text-align:center">
    2020-07-31
   </td>
   <td style="text-align:center">
    $942
   </td>
  </tr>
  <tr>
   <td style="text-align:center">
    2020-04-30
   </td>
   <td style="text-align:center">
    $1,021
   </td>
  </tr>
  <tr>
   <td style="text-align:center">
    2020-01-31
   </td>
   <td style="text-align:center">
    $2,194
   </td>
  </tr>
  <tr>
   <td style="text-align:center">
    2019-10-31
   </td>
   <td style="text-align:center">
    $1,439
   </td>
  </tr>
  <tr>
   <td style="text-align:center">
    2019-07-31
   </td>
   <td style="text-align:center">
    $1,286
   </td>
  </tr>
  <tr>
   <td style="text-align:center">
    2019-04-30
   </td>
   <td style="text-align:center">
    $1,548
   </td>
  </tr>
  <tr>
   <td style="text-align:center">
    2019-01-31
   </td>
   <td style="text-align:center">
    $3,063
   </td>
  </tr>
  <tr>
   <td style="text-align:center">
    2018-10-31
   </td>
   <td style="text-align:center">
    $1,935
   </td>
  </tr>
  <tr>
   <td style="text-align:center">
    2018-07-31
   </td>
   <td style="text-align:center">
    $1,501
   </td>
  </tr>
  <tr>
   <td style="text-align:center">
    2018-04-30
   </td>
   <td style="text-align:center">
    $1,786
   </td>
  </tr>
  <tr>
   <td style="text-align:center">
    2018-01-31
   </td>
   <td style="text-align:center">
    $2,825
   </td>
  </tr>
  <tr>
   <td style="text-align:center">
    2017-10-31
   </td>
   <td style="text-align:center">
    $1,989
   </td>
  </tr>
  <tr>
   <td style="text-align:center">
    2017-07-31
   </td>
   <td style="text-align:center">
    $1,688
   </td>
  </tr>
  <tr>
   <td style="text-align:center">
    2017-04-30
   </td>
   <td style="text-align:center">
    $2,046
   </td>
  </tr>
  <tr>
   <td style="text-align:center">
    2017-01-31
   </td>
   <td style="text-align:center">
    $2,403
   </td>
  </tr>
  <tr>
   <td style="text-align:center">
    2016-10-31
   </td>
   <td style="text-align:center">
    $1,959
   </td>
  </tr>
  <tr>
   <td style="text-align:center">
    2016-07-31
   </td>
   <td style="text-align:center">
    $1,632
   </td>
  </tr>
  <tr>
   <td style="text-align:center">
    2016-04-30
   </td>
   <td style="text-align:center">
    $1,972
   </td>
  </tr>
  <tr>
   <td style="text-align:center">
    2016-01-31
   </td>
   <td style="text-align:center">
    $3,525
   </td>
  </tr>
  <tr>
   <td style="text-align:center">
    2015-10-31
   </td>
   <td style="text-align:center">
    $2,016
   </td>
  </tr>
  <tr>
   <td style="text-align:center">
    2015-07-31
   </td>
   <td style="text-align:center">
    $1,762
   </td>
  </tr>
  <tr>
   <td style="text-align:center">
    2015-04-30
   </td>
   <td style="text-align:center">
    $2,061
   </td>
  </tr>
  <tr>
   <td style="text-align:center">
    2015-01-31
   </td>
   <td style="text-align:center">
    $3,476
   </td>
  </tr>
  <tr>
   <td style="text-align:center">
    2014-10-31
   </td>
   <td style="text-align:center">
    $2,092
   </td>
  </tr>
  <tr>
   <td style="text-align:center">
    2014-07-31
   </td>
   <td style="text-align:center">
    $1,731
   </td>
  </tr>
  <tr>
   <td style="text-align:center">
    2014-04-30
   </td>
   <td style="text-align:center">
    $1,996
   </td>
  </tr>
  <tr>
   <td style="text-align:center">
    2014-01-31
   </td>
   <td style="text-align:center">
    $3,684
   </td>
  </tr>
  <tr>
   <td style="text-align:center">
    2013-10-31
   </td>
   <td style="text-align:center">
    $2,107
   </td>
  </tr>
  <tr>
   <td style="text-align:center">
    2013-07-31
   </td>
   <td style="text-align:center">
    $1,384
   </td>
  </tr>
  <tr>
   <td style="text-align:center">
    2013-04-30
   </td>
   <td style="text-align:center">
    $1,865
   </td>
  </tr>
  <tr>
   <td style="text-align:center">
    2013-01-31
   </td>
   <td style="text-align:center">
    $3,562
   </td>
  </tr>
  <tr>
   <td style="text-align:center">
    2012-10-31
   </td>
   <td style="text-align:center">
    $1,773
   </td>
  </tr>
  <tr>
   <td style="text-align:center">
    2012-07-31
   </td>
   <td style="text-align:center">
    $1,550
   </td>
  </tr>
  <tr>
   <td style="text-align:center">
    2012-04-30
   </td>
   <td style="text-align:center">
    $2,002
   </td>
  </tr>
  <tr>
   <td style="text-align:center">
    2012-01-31
   </td>
   <td style="text-align:center">
    $3,579
   </td>
  </tr>
  <tr>
   <td style="text-align:center">
    2011-10-31
   </td>
   <td style="text-align:center">
    $1,947
   </td>
  </tr>
  <tr>
   <td style="text-align:center">
    2011-07-31
   </td>
   <td style="text-align:center">
    $1,744
   </td>
  </tr>
  <tr>
   <td style="text-align:center">
    2011-04-30
   </td>
   <td style="text-align:center">
    $2,281
   </td>
  </tr>
  <tr>
   <td style="text-align:center">
    2011-01-31
   </td>
   <td style="text-align:center">
    $3,693
   </td>
  </tr>
  <tr>
   <td style="text-align:center">
    2010-10-31
   </td>
   <td style="text-align:center">
    $1,899
   </td>
  </tr>
  <tr>
   <td style="text-align:center">
    2010-07-31
   </td>
   <td style="text-align:center">
    $1,799
   </td>
  </tr>
  <tr>
   <td style="text-align:center">
    2010-04-30
   </td>
   <td style="text-align:center">
    $2,083
   </td>
  </tr>
  <tr>
   <td style="text-align:center">
    2010-01-31
   </td>
   <td style="text-align:center">
    $3,524
   </td>
  </tr>
  <tr>
   <td style="text-align:center">
    2009-10-31
   </td>
   <td style="text-align:center">
    $1,835
   </td>
  </tr>
  <tr>
   <td style="text-align:center">
    2009-07-31
   </td>
   <td style="text-align:center">
    $1,739
   </td>
  </tr>
  <tr>
   <td style="text-align:center">
    2009-04-30
   </td>
   <td style="text-align:center">
    $1,981
   </td>
  </tr>
  <tr>
   <td style="text-align:center">
    2009-01-31
   </td>
   <td style="text-align:center">
    $3,492
   </td>
  </tr>
  <tr>
   <td style="text-align:center">
    2008-10-31
   </td>
   <td style="text-align:center">
    $1,696
   </td>
  </tr>
  <tr>
   <td style="text-align:center">
    2008-07-31
   </td>
   <td style="text-align:center">
    $1,804
   </td>
  </tr>
  <tr>
   <td style="text-align:center">
    2008-04-30
   </td>
   <td style="text-align:center">
    $1,814
   </td>
  </tr>
  <tr>
   <td style="text-align:center">
    2008-01-31
   </td>
   <td style="text-align:center">
    $2,866
   </td>
  </tr>
  <tr>
   <td style="text-align:center">
    2007-10-31
   </td>
   <td style="text-align:center">
    $1,611
   </td>
  </tr>
  <tr>
   <td style="text-align:center">
    2007-07-31
   </td>
   <td style="text-align:center">
    $1,338
   </td>
  </tr>
  <tr>
   <td style="text-align:center">
    2007-04-30
   </td>
   <td style="text-align:center">
    $1,279
   </td>
  </tr>
  <tr>
   <td style="text-align:center">
    2007-01-31
   </td>
   <td style="text-align:center">
    $2,304
   </td>
  </tr>
  <tr>
   <td style="text-align:center">
    2006-10-31
   </td>
   <td style="text-align:center">
    $1,012
   </td>
  </tr>
  <tr>
   <td style="text-align:center">
    2006-07-31
   </td>
   <td style="text-align:center">
    $963
   </td>
  </tr>
  <tr>
   <td style="text-align:center">
    2006-04-30
   </td>
   <td style="text-align:center">
    $1,040
   </td>
  </tr>
  <tr>
   <td style="text-align:center">
    2006-01-31
   </td>
   <td style="text-align:center">
    $1,667
   </td>
  </tr>
  <tr>
   <td style="text-align:center">
    2005-10-31
   </td>
   <td style="text-align:center">
    $534
   </td>
  </tr>
  <tr>
   <td style="text-align:center">
    2005-07-31
   </td>
   <td style="text-align:center">
    $416
   </td>
  </tr>
  <tr>
   <td style="text-align:center">
    2005-04-30
   </td>
   <td style="text-align:center">
    $475
   </td>
  </tr>
  <tr>
   <td style="text-align:center">
    2005-01-31
   </td>
   <td style="text-align:center">
    $709
   </td>
  </tr>
 </tbody>
</table>

/tmp/wsuser/ipykernel_789/1932474816.py:23: FutureWarning: The default value of regex will change from True to False in a future version.
  gme_revenue["Revenue"] = gme_revenue['Revenue'].str.replace(',|\$',"")

Display the last five rows of the gme_revenue dataframe using the tail function. Take a screenshot of the results.

In [19]:
gme_revenue.tail()
Out[19]:
Date Revenue
63 2006-01-31 1667
64 2005-10-31 534
65 2005-07-31 416
66 2005-04-30 475
67 2005-01-31 709

Question 5: Plot Tesla Stock Graph

Use the make_graph function to graph the Tesla Stock Data, also provide a title for the graph. The structure to call the make_graph function is make_graph(tesla_data, tesla_revenue, 'Tesla'). Note the graph will only show data upto June 2021.

In [20]:
make_graph(tesla_data, tesla_revenue, 'Tesla')

Question 6: Plot GameStop Stock Graph

Use the make_graph function to graph the GameStop Stock Data, also provide a title for the graph. The structure to call the make_graph function is make_graph(gme_data, gme_revenue, 'GameStop'). Note the graph will only show data upto June 2021.

In [21]:
make_graph(gme_data, gme_revenue, 'GameStop')

About the Authors:

Joseph Santarcangelo has a PhD in Electrical Engineering, his research focused on using machine learning, signal processing, and computer vision to determine how videos impact human cognition. Joseph has been working for IBM since he completed his PhD.

Azim Hirjani

Change Log

Date (YYYY-MM-DD) Version Changed By Change Description
2020-11-10 1.1 Malika Singla Deleted the Optional part
2020-08-27 1.0 Malika Singla Added lab to GitLab

© IBM Corporation 2020. All rights reserved.